from django.http import JsonResponse

from .res_code import Code

# 用于处理json格式转化功能
def to_json_data(errno: object = Code.OK, errmsg: object = '', data: object = None, kwargs: object = None) -> object:
    json_dict = {'errno': errno, 'errmsg': errmsg, 'data': data}

    if kwargs and isinstance(kwargs, dict):
        json_dict.update(kwargs)

    return JsonResponse(json_dict)